namespace Crux.Core.MongoDb;
/// <summary>
/// MongoDbConnectionHelmOfT
/// </summary>
public class MongoDbConnectionHelm<TContext>
        : IMongoDbConnectionHelm<TContext>
        where TContext : MongoDBContext
{
    #region private fields
    private readonly MongoClientSettings? mongoClientSettings;
    private readonly Lazy<IMongoClient> internalMongoClient;
    #endregion  private fields

    #region .ctor
    /// <summary>
    /// 
    /// </summary>
    /// <param name="option"></param>
    public MongoDbConnectionHelm(IOptions<MongoDbOption<TContext>> option)
    {
        Requires.NotNull(option, nameof(option));
        Requires.NotNull(option.Value, nameof(option.Value));
        Requires.NotNull(option.Value.MongoClientSettings, nameof(option.Value.MongoClientSettings));

        this.mongoClientSettings = option.Value.MongoClientSettings;
        this.internalMongoClient = new Lazy<IMongoClient>(() => new MongoClient(this.mongoClientSettings));
    }
    #endregion .ctor

    #region implements IMongoDbConnectionHelm
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public IMongoClient GetMongoClient() => internalMongoClient.Value;
    #endregion implements IMongoDbConnectionHelm


}